/**
 * 动态修改模型的 modelMatrix 实现平移动画
 */
export function animateModelMatrix(feature: any, direction: any, distance: number, duration: number) {
    const startMatrix = Cesium.Matrix4.clone(feature.modelMatrix);
    const translation = Cesium.Cartesian3.multiplyByScalar(direction, distance, new Cesium.Cartesian3());

    const start = performance.now();

    function step(time: number) {
        const t = Math.min((time - start) / duration, 1);
        const offset = Cesium.Cartesian3.multiplyByScalar(translation, t, new Cesium.Cartesian3());

        const newMatrix = Cesium.Matrix4.clone(startMatrix);
        Cesium.Matrix4.setTranslation(newMatrix, offset, newMatrix);
        feature.modelMatrix = newMatrix;

        if (t < 1) {
            requestAnimationFrame(step);
        }
    }

    requestAnimationFrame(step);
}
